package com.xxkk.gameCore.net.sql.pojo;

import com.alibaba.fastjson.JSONObject;
import com.google.protobuf.Message;
import com.xxkk.gameCore.proto.bo.AccountProBuf;
import com.xxkk.utils.TimeUtil;

import java.util.Date;

public class UserInfo {
    private Integer id;

    private String account;

    private String password;

    private String name;

    private String platformId;

    private String phoneNumber;

    private String phoneModel;

    private String lastLoginIp;

    private Date updated;// 刷新玩家信息时间

    private String registerIp;

    private Date created;// 注册时间

    private Integer age;

    private Integer sex;

    private String channel;

    private Date birthday;

    private Object state;

    public UserInfo(Integer id, String account, String password, String name, String platformId, String phoneNumber, String phoneModel, String lastLoginIp, Date updated, String registerIp, Date created, Integer age, Integer sex, String channel, Date birthday, Object state) {
        this.id = id;
        this.account = account;
        this.password = password;
        this.name = name;
        this.platformId = platformId;
        this.phoneNumber = phoneNumber;
        this.phoneModel = phoneModel;
        this.lastLoginIp = lastLoginIp;
        this.updated = updated;
        this.registerIp = registerIp;
        this.created = created;
        this.age = age;
        this.sex = sex;
        this.channel = channel;
        this.birthday = birthday;
        this.state = state;
    }

    public UserInfo() {
        super();
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getAccount() {
        return account;
    }

    public void setAccount(String account) {
        this.account = account;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPlatformId() {
        return platformId;
    }

    public void setPlatformId(String platformId) {
        this.platformId = platformId;
    }

    public String getPhoneNumber() {
        return phoneNumber;
    }

    public void setPhoneNumber(String phoneNumber) {
        this.phoneNumber = phoneNumber;
    }

    public String getPhoneModel() {
        return phoneModel;
    }

    public void setPhoneModel(String phoneModel) {
        this.phoneModel = phoneModel;
    }

    public String getLastLoginIp() {
        return lastLoginIp;
    }

    public void setLastLoginIp(String lastLoginIp) {
        this.lastLoginIp = lastLoginIp;
    }

    public Date getUpdated() {
        return updated;
    }

    public void setUpdated(Date updated) {
        this.updated = updated;
    }

    public String getRegisterIp() {
        return registerIp;
    }

    public void setRegisterIp(String registerIp) {
        this.registerIp = registerIp;
    }

    public Date getCreated() {
        return created;
    }

    public void setCreated(Date created) {
        this.created = created;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    public Integer getSex() {
        return sex;
    }

    public void setSex(Integer sex) {
        this.sex = sex;
    }

    public String getChannel() {
        return channel;
    }

    public void setChannel(String channel) {
        this.channel = channel;
    }

    public Date getBirthday() {
        return birthday;
    }

    public void setBirthday(Date birthday) {
        this.birthday = birthday;
    }

    public Object getState() {
        return state;
    }

    public void setState(Object state) {
        this.state = state;
        this.setUpdated(TimeUtil.getDate());
    }

    @Override
    public String toString() {
        return "UserInfo{" +
                "id=" + id +
                ", account='" + account + '\'' +
                ", password='" + password + '\'' +
                ", name='" + name + '\'' +
                ", platformId='" + platformId + '\'' +
                ", phoneNumber='" + phoneNumber + '\'' +
                ", phoneModel='" + phoneModel + '\'' +
                ", lastLoginIp='" + lastLoginIp + '\'' +
                ", updated=" + updated +
                ", registerIp='" + registerIp + '\'' +
                ", created=" + created +
                ", age=" + age +
                ", sex=" + sex +
                ", channel='" + channel + '\'' +
                ", birthday=" + birthday +
                ", state=" + state +
                '}';
    }

    public static Message.Builder builder(UserInfo userInfo) {
        AccountProBuf.UserInfoProto.Builder builder = AccountProBuf.UserInfoProto.newBuilder();
        if (userInfo.getId() != null) builder.setId(userInfo.getId());
        builder.setAccount(userInfo.getAccount());
        builder.setPassword(userInfo.getPassword());
        if (userInfo.getName() != null) builder.setName(userInfo.getName());
        if (userInfo.getPlatformId() != null) builder.setPlatformId(userInfo.getPlatformId());
        if (userInfo.getPhoneNumber() != null) builder.setPhoneNumber(userInfo.getPhoneNumber());
        if (userInfo.getPhoneModel() != null) builder.setPhoneModel(userInfo.getPhoneModel());
        if (userInfo.getLastLoginIp() != null) builder.setLastLoginIp(userInfo.getLastLoginIp());
        if (userInfo.getUpdated() != null) builder.setLastLoginTime(userInfo.getUpdated().getTime());
        if (userInfo.getRegisterIp() != null) builder.setRegisterIp(userInfo.getRegisterIp());
        if (userInfo.getCreated() != null) builder.setRegisterTime(userInfo.getCreated().getTime());
        if (userInfo.getAge() != null) builder.setAge(userInfo.getAge());
        if (userInfo.getSex() != null) builder.setSex(userInfo.getSex());
        if (userInfo.getChannel() != null) builder.setChannel(userInfo.getChannel());
        if (userInfo.getBirthday() != null) builder.setBirthday(userInfo.getBirthday().getTime());
        if (userInfo.getState() != null) builder.setState(JSONObject.toJSONString(userInfo.getState()));
        return builder;
    }
}